<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h2>总价：{{allPrice}}元</h2>
        <h2>总价：{{allPrice2()}}元</h2>
        
    </div>
</body>
<script src="./vue.min.js"></script>
<script>
    var vm = new Vue({
        el:"#app",
        data:{
           goods:[
           {
                name:"手机",
                num:1,
                price:2080
            },
            {
                name:"手表",
                num:2,
                price:3800
            },
            {
                name:"戒指",
                num:1,
                price:22000
            }
           ]
        },
        methods: {
            allPrice2(){
                var all = 0;
                this.goods.forEach(item => {
                    all += item.num*item.price
                });
                return all;
            }
        },
        computed:{
            allPrice:function(){
                var all = 0;
                this.goods.forEach(item => {
                    all += item.num*item.price
                });
                return all;
            }
        }
    })


</script>
</html>